<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="author" content="zxh">
    <title>订单</title>
    <style>
        * {
            box-sizing: border-box;
            cursor: pointer;
        }
        
        ul,
        li {
            margin: 0;
            padding: 0;
            list-style: none;
        }
        
        #box {
            width: 200px;
            margin: 50px auto;
        }
        
        #box .btn {
            float: left;
            width: 100px;
            height: 30px;
            line-height: 30px;
            text-align: center;
            position: relative;
        }
        
        #box .btn span {
            display: inline-block;
            width: 100%;
            height: 100%;
            border: 1px solid #ccc;
        }
        
        #box .btn span.right {
            position: absolute;
            left: -1px;
        }
        
        #box ul {
            width: 100%;
            border: 1px solid #ccc;
            position: absolute;
            top: 29px;
            left: 0;
            display: none;
        }
        
        #box ul.right-list {
            left: -1px;
        }
        
        #box ul li {
            border-bottom: 1px solid #ccc;
        }
        
        #box ul li:last-child {
            border: none;
        }
        
        #box ul li:hover {
            background-color: #ccc;
        }
        
        #box p {
            text-align: center;
            margin-top: 120px;
        }
    </style>
</head>

<body>
    <div id="box">
        <div class="btn">
            <span class="left">销售订单</span>
            <ul class="left-list">
                <li>销售1</li>
                <li>销售2</li>
                <li>销售3</li>
            </ul>
        </div>
        <div class="btn">
            <span class="right">消费订单</span>
            <ul class="right-list">
                <li>消费1</li>
                <li>消费2</li>
                <li>消费3</li>
            </ul>
        </div>
        <div style="clear: both"></div>
        <p></p>
    </div>
</body>

</html>
<script src="js/jquery.js"></script>
<script>
    // 记录每次获取的内容
    var result;
    console.log('re = ' + result);
    console.log('p = ' + $('p').html());
    $('#box .btn').hover(function () {
        // 鼠标进来显示列表
        $(this).find('ul').show()
        // 当列表显示时 给li添加点击事件 并获取内容显示到页面上
        $(this).find('ul li').each(function () {
            $(this).click(function () {
                // 记录当前选中的内容
                result = $(this).html()
                console.log('re=' + result)
                // 当每次点击获取的内容不一样时 再去更新p标签的内容
                if ($('p').html() != result) {
                    // 显示结果
                    $('p').html($(this).html())
                    console.log('新的内容')
                }
                //找到li标签的父元素ul 让其隐藏
                $(this).parent().hide()
            })
        })
    }, function () {
        // 鼠标出去，隐藏列表
        $(this).find('ul').hide()
    })

</script>